#!/usr/bin/env node
let browserify = require('browserify')
let envify     = require('envify')
let path       = require('path')
let glob       = require('glob')
let env        = require('node-env-file')
let fs         = require('fs')
let entries    = glob.sync('./test/*-test-electron.js')

// add a window.close for the browser-run env
entries.push(path.join(__dirname, '..', 'test', '_env-browser-close.js'))

let hasVars = process.env.SLACK_BOT_TOKEN &&
              process.env.SLACK_CLIENT_ID &&
              process.env.SLACK_CLIENT_SECRET
if (!hasVars) {
  // load up the env vars
  env(path.join(__dirname, '..', '.env'))
}

// build the test suite and pipe to stdout
browserify({entries})
  .external('electron')
  .transform(envify)
  .bundle()
  .pipe(process.stdout)
